package com.cskaoyan.utils.wx;

import cn.hutool.extra.spring.SpringUtil;
import com.cskaoyan.bean.CskaoyanmallUser;
import com.cskaoyan.myenum.ResultEnum;
import com.cskaoyan.service.UserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.util.ObjectUtils;

/**
 * @author:
 * @DateTime: 2021/4/11 9:01 下午
 * @description:
 */
public class UserUtil {


    public static Integer getUserId(){
        Subject subject = SecurityUtils.getSubject();
        String principal = (String) subject.getPrincipal();
        if(ObjectUtils.isEmpty(principal)){
            return ResultEnum.USER_NOT_LOGIN.getCode();
        }
        UserService userService = SpringUtil.getBean("userServiceImpl");
        CskaoyanmallUser user = userService.selectUserByName(principal);
        return user.getId();

    }
}
